function t() {
  1 == a.data.info.is_dynamic ? wx.navigateTo({
    url: "/pages/emotimake/emotimake?micro_id=" + i + "&log_id=" + o
  }) : wx.navigateTo({
    url: "/pages/make/make?micro_id=" + i + "&log_id=" + o
  });
}

function e(t) {
  for (var e = a.data.rulelist, i = {
    pay_code: "",
    old_price: 0,
    now_price: 0
  }, o = 0; o < e.length; o++) if (t > 0) {
    if (e[o].pay_day > 0) {
      i = e[o];
      break;
    }
  } else if (e[o].pay_gold > 0) {
    i = e[o];
    break;
  }
  return i;
}

var a, i, o, r, n, c = require("../../utils/util.js"), p = getApp().globalData.url.imgurl;

Page({
  data: {
    imgurl: p,
    paywarp: !0,
    paytype: 1,
    curcode: "",
    old_price: 0,
    now_price: 0,
    tipshow: 0
  },
  onLoad: function (t) {
    i = t.micro_id, a = this;
    var e = wx.getSystemInfoSync();
    n = e.platform, this.setData({
      platform: e.platform
    });
  },
  onShow: function () {
    o = 0, r = 1, c.getToken(function (t) {
      c.sendrequest("posterapi/getposter", "POST", {
        token: t,
        id: i
      }, function (t) {
        1 == t.status && (a.setData({
          info: t.data,
          tipshow: t.data.tipshow
        }), t.data.ispay > 0 && (o = t.data.log_id));
      });
    }), c.sendrequest("payapi/payrule", "POST", "", function (t) {
      1 == t.status && a.setData({
        rulelist: t.data.paylist
      });
    });
  },
  onShareAppMessage: function (t) {
    return {
      title: "小婷海报",
      path: "pages/poster/poster?micro_id=" + i,
      success: function (t) { },
      fail: function (t) { }
    };
  },
  changetype: function (t) {
    var a = 1 == this.data.paytype ? 0 : 1, i = e(a);
    this.setData({
      paytype: a,
      old_price: i.old_price,
      now_price: i.now_price,
      curcode: i.pay_code
    });
  },
  more: function (t) {
    wx.reLaunch({
      url: "/pages/index/index"
    });
  },
  showpay: function (t) {
    var a = e(t.currentTarget.dataset.type);
    this.setData({
      paytype: t.currentTarget.dataset.type,
      paywarp: !1,
      old_price: a.old_price,
      now_price: a.now_price,
      curcode: a.pay_code
    });
  },
  selectpay: function (t) {
    this.setData({
      curcode: t.currentTarget.dataset.code
    });
    for (var e = a.data.rulelist, i = 0; i < e.length; i++) t.currentTarget.dataset.code == e[i].pay_code && this.setData({
      old_price: e[i].old_price,
      now_price: e[i].now_price
    });
  },
  closewarp: function (t) {
    this.setData({
      paywarp: !0
    });
  },
  checkboxChange: function (t) {
    r = t.detail.value[0] > 0 ? 1 : 0;
  },
  getsignpack: function (t) {
    if (r < 1) return wx.showToast({
      title: "请同意会员协议"
    }), !1;
    a.data.curcode && c.getToken(function (t) {
      c.sendrequest("payapi/createorder", "POST", {
        token: t,
        code: a.data.curcode
      }, function (t) {
        1 == t.status && wx.requestPayment({
          timeStamp: t.data.timeStamp,
          nonceStr: t.data.nonceStr,
          package: "prepay_id=" + t.data.prepayId,
          signType: "MD5",
          paySign: t.data.paySign,
          success: function (t) {
            wx.showToast({
              title: "支付成功",
              icon: "success",
              duration: 2e3
            }), wx.reLaunch({
              url: "/pages/poster/poster?micro_id=" + i
            });
          },
          fail: function (t) { }
        });
      });
    });
  },
  changeme: function (r) {
    a.data.info.ispay > 0 && o > 0 ? t() : c.getToken(function (r) {
      wx.showLoading({
        title: "请求中",
        mask: !0
      }), c.sendrequest("posterapi/payposter", "POST", {
        token: r,
        id: i
      }, function (i) {
        if (wx.hideLoading(), 1 == i.status) o = i.data.log_id, t(); else if (3 == i.status) {
          if (c.malert("金币不足"), "ios" != n) {
            var r = e(1);
            a.setData({
              paytype: 1,
              paywarp: !1,
              old_price: r.old_price,
              now_price: r.now_price,
              curcode: r.pay_code
            });
          }
        } else c.malert("网络错误");
      });
    });
  },
  collect: function (t) {
    c.addcollect(t.currentTarget.dataset.id);
  }
});